from manim import *

class IntegerAddition(Scene):
    def construct(self):
        # 创建数轴
        number_line = NumberLine(
            x_range=[-10, 10, 1],  # 数轴范围从 -10 到 10，每个刻度为 1
            length=10,             # 数轴的长度
            color=BLUE,
            include_numbers=True,  # 显示刻度数字
        )
        self.play(Create(number_line))

        # 创建并显示整数点
        start_point = Dot(point=number_line.n2p(2), color=YELLOW)  # 起始点位置为 2
        self.play(FadeIn(start_point))
        start_label = MathTex("2").next_to(start_point, UP)
        self.play(Write(start_label))

        # 加法运算，移动到新的位置
        shift_amount = 3  # 需要加的整数
        self.play(start_point.animate.shift(shift_amount * RIGHT), run_time=2)  # 向右移动3个单位
        end_label = MathTex("2 + 3 = 5").next_to(start_point, UP)
        self.play(Transform(start_label, end_label))

        # 显示加法过程中的箭头
        arrow = Arrow(start=number_line.n2p(2), end=number_line.n2p(5), buff=0, color=RED)
        self.play(Create(arrow))

        # 加上文本说明
        explanation = Text("2 + 3 = 5", font_size=24).to_edge(DOWN)
        self.play(Write(explanation))

        # 保持屏幕显示几秒钟
        self.wait(3)
